package com.sign2024.sign2024project.goodsmaterials.controller.test;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.sign2024.sign2024core.entry.goodsmaterials.WzHistoryData;

import java.util.List;
import java.util.Map;

public class CustomExcelListener extends AnalysisEventListener<Map<Integer, String>> {
    private Map<Integer, String> headerMap;
    private List<WzHistoryData> dataList;

    public CustomExcelListener(List<WzHistoryData> dataList) {
        this.dataList = dataList;
    }

    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        this.headerMap = headMap;
    }

    @Override
    public void invoke(Map<Integer, String> row, AnalysisContext context) {
        WzHistoryData data = new WzHistoryData();
        for (Map.Entry<Integer, String> entry : row.entrySet()) {
            String headerName = headerMap.get(entry.getKey());
            String cellValue = entry.getValue();
            if ("技术抽取专业".equals(headerName) || "技术抽取专业2".equals(headerName) || "技术抽取专业3".equals(headerName)) {
                data.setSignMajor(cellValue);
            } else {
                // 处理其他字段
                // 例如：data.setOtherField(cellValue);
            }
        }
        dataList.add(data);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        // 所有数据解析完成后的操作
    }
}